package com.hermes.action.json;

import java.util.ArrayList;
import java.util.List;

import com.hermes.biz.common.model.item.ItemDO;
import com.hermes.biz.common.model.item.ItemUserRelationDO;
import com.hermes.biz.common.model.result.ItemResultDO;
import com.hermes.biz.manager.item.UserItemRelationManager;
import com.hermes.biz.manager.item.impl.ItemOperateManagerImpl;
import com.hermes.common.action.AsynBaseAction;
import com.hermes.common.util.ParameterParserUtil;

public class AsynGetItemsPersonHome extends AsynBaseAction{
	
	private static final long serialVersionUID = -2733669038890093289L;
	public List<ItemUserRelationDO> itemUserRelationList;
	
	UserItemRelationManager userItemRelationManager;

	public List<ItemDO> itemDOList;
	
	ItemOperateManagerImpl itemOperator;

	public int itemLVcount =0;
	
	@Override
	public String execute() throws Exception {
		itemDOList = new ArrayList<ItemDO>();
		long userId = Long.valueOf(ParameterParserUtil.getParameter("uid"));		
		itemUserRelationList = new ArrayList<ItemUserRelationDO>();
		itemUserRelationList = userItemRelationManager.getUserInterestedItems(userId);
		itemLVcount = itemUserRelationList.size();
		for(ItemUserRelationDO itemUserRela : itemUserRelationList){
			ItemResultDO resultDO = itemOperator.getSingleItemByItemId(itemUserRela.getInterestedItemId());
			if(resultDO!=null){
				itemDOList.add(resultDO.getModule());
				
			}else{
				System.out.println("no result for this item id");
			}			
		}		
		return SUCCESS;
	}

	//getters and setters
	public ItemOperateManagerImpl getItemOperator() {
		return itemOperator;
	}

	public void setItemOperator(ItemOperateManagerImpl itemOperator) {
		this.itemOperator = itemOperator;
	}
	
	public UserItemRelationManager getUserItemRelationManager() {
		return userItemRelationManager;
	}

	public void setUserItemRelationManager(
			UserItemRelationManager userItemRelationManager) {
		this.userItemRelationManager = userItemRelationManager;
	}
}
